package com.longcheer.weibo;

import com.longcheer.weibo.util.Utils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
//import android.os.Handler;
//import android.os.Message;
//import android.util.Log;
import android.widget.ImageView;

public class DetailImageActivity extends Activity {
    
    private ProgressDialog mProgress;
    private ImageView mImage;
    private String mUrl;
    
//    private static final int MSG_DOWNLOAD_BEGIN = 0;
//    private static final int MSG_DOWNLOAD_END = 1;
//    private static final int MSG_DOWNLOAD_ERR = 2;
//    
//    private Handler mHandler = new Handler() {
//
//        @Override
//        public void handleMessage(Message msg) {
//            switch (msg.what) {
//            case MSG_DOWNLOAD_BEGIN:
//                
//            }
//        }
//        
//    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.detail_image);
        
        mImage = (ImageView)findViewById(R.id.iv_large);
        
        //mHandler.sendEmptyMessage(MSG_DOWNLOAD_BEGIN);
        
        mUrl = getIntent().getStringExtra("large_url");
        if (Utils.isEmpty(mUrl)) {
            
        } else { 
        
            String title = getResources().getString(R.string.app_name);
            String message = getResources().getString(R.string.loading);
            mProgress = ProgressDialog.show(this, title, message);
        
            ImageManager.getInstance().loadImage(mUrl, ImageManager.SOURCE_IMAGE, new ImageManager.Callback() {
                @Override
                public void imageLoaded(Bitmap bitmap, String imageUrl) {
                    mProgress.dismiss();
                    mImage.setImageBitmap(bitmap);
                }
            });
        }   
    }

    @Override
    protected void onPause() {
        if (!Utils.isEmpty(mUrl)) {
            ImageManager.getInstance().removeBitmap(mUrl);
        }
        super.onPause();
    }
}
